package com.example.demo.web.car;

import com.example.demo.car.vo.UserInfo;
import com.example.demo.interceptor.CarInterceptor;
import com.example.demo.utils.SysUtils;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.StringRedisTemplate;
import org.springframework.stereotype.Controller;
import org.springframework.util.StringUtils;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;

import javax.servlet.http.HttpSession;

@Slf4j
@Controller
@RequestMapping("car")
public class CarController {

    @Autowired
    StringRedisTemplate redisTemplate;

    /**
     * 浏览器有个cookie保存一个月作为标识。一个月后过期，如果第一次使用购物车，都会给一个临时用户身份
     * 每次访问会带上这个cookie
     * <p>
     * 登录：session有
     */
    @GetMapping("page")
    public String catListPage(HttpSession session) {

        Object attribute = session.getAttribute(SysUtils.LOGIN_NAME);
        //快速找打用户信息
        ThreadLocal<UserInfo> threadLocal = CarInterceptor.threadLocal;
        UserInfo userInfo = threadLocal.get();
        System.out.println(userInfo);

        return "";
    }

    @RequestMapping("addcar")
    public void addCat() {

        //bound是啥
        redisTemplate.boundHashOps("");
    }


}
